import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;



public class MenuLog {

	private static volatile MenuLog instance = null;
	private ArrayList<String> log;
	
	private MenuLog() {
		log = new ArrayList<String>();
		
	}
	public static MenuLog getInstance() {
		if (instance == null) {
			synchronized (MenuLog.class) {
				if (instance == null) {
					instance = new MenuLog();
				}
			}
		}
		return instance;
	}
	public void addLog(String str){
		log.add(str + " at " + Calendar.getInstance().getTime() + "\n");
		this.writeToFile("log.txt", log);
	}
	
	public void writeToFile(String filename, ArrayList<String> logReport) {
        FileWriter fw;
        try {
            fw = new FileWriter(filename,true);
            for(String arr : logReport)
              {
            	fw.write(arr);
            
              }
        	fw.close();
        }
        
        // message and stop if file not found
        catch (FileNotFoundException fnf) {
            System.out.println(filename + " not found ");
            System.exit(0);
        }
        // stack trace here because we don't expect to come here
        catch (IOException ioe) {
            ioe.printStackTrace();
            System.exit(1);
        }
    }
}
